package com.frxuexi.park2301.my

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.alibaba.android.arouter.facade.annotation.Route
import com.frxuexi.lib_base.entity.MyApporve
import com.frxuexi.lib_base.entity.VisitStatus
import com.frxuexi.lib_base.mvvm.BaseActivity
import com.frxuexi.park2301.R
import com.frxuexi.park2301.databinding.ActivityMyApproveBinding
import com.frxuexi.visit.adapter.VisitAdapter
import dagger.hilt.android.AndroidEntryPoint

@Route(path = "/app/MyApproveActivity")
@AndroidEntryPoint
class MyApproveActivity : BaseActivity<ActivityMyApproveBinding,MyViewModel>() {
    val approveStatusAdapter by lazy { ApproveStatusAdapter() }
    val approveAdapter by lazy { MyApproveAdapter() }
    val list= mutableListOf<MyApporve>()
    override fun initData() {
        vm.myParkData.observe(this){
            it.forEach { it.itemType=0 }
            list.addAll(it)
            approveAdapter.addData(it)
            approveAdapter.notifyDataSetChanged()
        }

        vm.myVisistData.observe(this){
            it.forEach { it.itemType=1 }
            list.addAll(it)
            approveAdapter.addData(it)
            approveAdapter.notifyDataSetChanged()
        }

        vm.myNewsData.observe(this){
            it.forEach { it.itemType=2 }
            list.addAll(it)
            approveAdapter.addData(it)
            approveAdapter.notifyDataSetChanged()
        }

    }

    override fun initView() {
        val statusList = listOf<VisitStatus>(
            VisitStatus("全部", true),
            VisitStatus("车位审核", false),
            VisitStatus("来访审核", false),
            VisitStatus("新闻审核", false)
        )
        approveStatusAdapter.addData(statusList)
        binding.appRv.apply {
            adapter=approveStatusAdapter
            layoutManager=LinearLayoutManager(this@MyApproveActivity,RecyclerView.HORIZONTAL,false)
        }

        approveStatusAdapter.setOnItemClickListener { adapter, view, position ->
            approveStatusAdapter.data.forEach {
                it.isCheck=false
            }
            approveStatusAdapter.data.get(position).isCheck=true
            approveStatusAdapter.notifyDataSetChanged()

            approveAdapter.data.clear()
            if(position==0){
                approveAdapter.addData(list)
            }else{
                approveAdapter.addData(list.filter { it.itemType== position-1})
            }
            approveAdapter.notifyDataSetChanged()
        }

        binding.rvApprove.apply {
            adapter=approveAdapter
            layoutManager=LinearLayoutManager(this@MyApproveActivity)
        }

        vm.getMyRarks()
        vm.getMyVisits()
        vm.getMyNews()
    }

}